package com.itheima.zuoye.zuoye4;


import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        ArrayList<Goods> list = new ArrayList<>();
        Goods goods = new Goods("iphone", 10);
        list.add(goods);
        list.add(new Goods("mac", 10));
        list.add(new Goods("ipad", 10));
        list.add(new Goods("airpods", 10));
        while (true) {
            // 打印实时清单
            for (int i = 0; i < list.size(); i++) {
                System.out.println("商品序号" + (i + 1) + ":" + list.get(i));
            }
            System.out.print("选择需要秒杀的商品序号（0 退出）：");
            Scanner scanner = new Scanner(System.in);
            while (!scanner.hasNextInt()) {          // 防止非数字
                scanner.next();
                System.out.print("请输入数字序号：");
            }
            int no = scanner.nextInt();
            if (no == 0) break;
            if (no < 1 || no > list.size()) {
                System.out.println("序号不存在！");
                continue;
            }
            System.out.println(list.get(no - 1).secKill());
            System.out.println("----------------------------------");
        }
        System.out.println("感谢参与秒杀！");

        }
    }

